package cn.tedu.administration.service.impl;

import cn.tedu.administration.mapper.GoodsMapper;
import cn.tedu.administration.pojo.dto.GoodsParam;
import cn.tedu.administration.pojo.entity.Goods;
import cn.tedu.administration.pojo.entity.Item;
import cn.tedu.administration.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class GoodsImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public void addGoodsApplication(GoodsParam goodsParam) {
        log.debug("传入的数据{}",goodsParam);
        Goods goods = new Goods();
        BeanUtils.copyProperties(goodsParam,goods);
        List<Item> items = goodsParam.getItems();
        if(items.size()> 0){
            for(int index = 0; index < items.size(); index++){
                goods.setCreateTime(new Date());
                goods.setItemName(items.get(index).getItemName());
                goods.setQuantity(items.get(index).getQuantity());
                goods.setReturned(items.get(index).getReturned());
                goodsMapper.addGoodsApplication(goods);
            }
        }
    }
}
